<?php

namespace App\Requests\Product;

use App\Models\Admin;
use App\Models\Product;
use App\Requests\BaseRequest;

/**
 * @property int $id 该数据
 * @property int $entity_id 实体对象ID
 * @property int $type 类型
 * @property string $name 套餐名称
 * @property string $thumbnail 封面
 * @property float $price 价格
 */
class StoreRequest extends BaseRequest
{
    /**
     * 定义规则信息
     *
     * @return array
     */
    public function rules()
    {
        return [
            'entity_id' => 'required|integer|min:1',
            'type'      => 'required|integer|min:1',
            'name'      => 'required|string|max:255|unique:' . Product::tableName() . ',name,' . ($this->id ?? 0) . ',id,is_delete,0,type,'.$this->type.',entity_id,' . $this->entity_id,
            'thumbnail' => 'required|string|max:255',
            'price'     => 'required|numeric|min:0',
            'sort'      => 'required|numeric|min:0',
        ];
    }

    /**
     * 定义字段对应的名称
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'id'        => '该数据',
            'entity_id' => '实体对象ID',
            'type'      => '类型',
            'name'      => '套餐名称',
            'thumbnail' => '封面',
            'price'     => '价格',
            'sort'      => '排序',
        ];
    }
}
